package com.system.controller;

import com.system.pojo.ContractGoods;
import com.system.service.ContractGoodsService;
import com.system.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yjymm
 * @date 2019-12-19 20:07
 */
@Controller
@ResponseBody
@RequestMapping("/contractGoods")
public class ContractGoodsController {

    @Autowired
    private ContractGoodsService cgs;

    @RequestMapping("/delete/{contractId}/{cgId}")
    public ResultVo<ContractGoods> delete(@PathVariable Integer contractId,@PathVariable Integer cgId){
        ResultVo<ContractGoods> resultVo = new ResultVo<ContractGoods>();
        try {
            resultVo = cgs.deleteByCidAndCgid(contractId,cgId);
        }catch (Exception e){
            e.printStackTrace();
            resultVo.setMessage("删除失败");
        }finally {
            return resultVo;
        }
    }

    @RequestMapping("/selectDetail/{cgId}")
    public ResultVo<ContractGoods> selectDetail(@PathVariable Integer cgId){
        ResultVo<ContractGoods> resultVo = new ResultVo<ContractGoods>();
        try {
            resultVo = cgs.selectDetailById(cgId);
        }catch (Exception e){
            e.printStackTrace();
            resultVo.setMessage("查询信息失败");
        }finally {
            return resultVo;
        }
    }


    @RequestMapping("/update")
    public ResultVo<ContractGoods> update(@RequestBody ContractGoods cg){
        ResultVo<ContractGoods> resultVo = new ResultVo<ContractGoods>();
        try {
            resultVo = cgs.update(cg);
        }catch (Exception e){
            e.printStackTrace();
            resultVo.setMessage("更新失败");
        }finally {
            return resultVo;
        }

    }
}
